function showDeviceTypeSearch() {
	window.location.href = "showDeviceTypeSearch.do";
}

function ajaxFindDeviceTypeSearchList(currentPage,pageSize) {
	$.ajax({
		type : "post",
		url : "ajaxDeviceTypeSearchList.do",
		data : {
			currentPage:currentPage,
			pageSize:pageSize,
		},
		success : function(msg) {
			$("#listDeviceTypeBox").html(msg);
		}

	});
}

function ajaxShowDeviceTypeEdit(id){
	$.ajax({
		type:"post",
		url:"ajaxShowDeviceTypeEdit.do",
		data:{id:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 750,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons: [
				          {
				        	  text: "保存",
				        	  click: function() {
				        		  ajaxSaveDeviceType(this);
				        	  }
				          },
				          {
				        	  text: "关闭",
				        	  click: function() {
				        		  $(this).dialog( "close" );
				        	  }
				          }
				          ]
			});
		}
	});
}

function ajaxShowDeviceTypePropertyEdit(id){
	$.ajax({
		type:"post",
		url:"ajaxShowDeviceTypePropertyEdit.do",
		data:{id:id},
		success:function(msg){
			$("#dialog2").html(msg);
			$("#dialog2").dialog({
				autoOpen: true,
				width: 800,
				title:$(".dialogtitle2").attr("title"),
				modal: true,
				buttons: [
				          {
				        	  text: "保存",
				        	  click: function() {
				        		  ajaxSaveDeviceTypeProperty(this);
				        	  }
				          },
				          {
				        	  text: "关闭",
				        	  click: function() {
				        		  $(this).dialog( "close" );
				        	  }
				          }
				          ]
			});
		}
	});
}

function ajaxShowDeviceTypePropertyView(id){
	$.ajax({
		type:"post",
		url:"ajaxShowDeviceTypePropertyView.do",
		data:{id:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 800,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons : [ {
					text : "关闭",
					click : function() {
						$(this).dialog("close");
					}
				} ]
			});
		}
	});
}

function ajaxSaveDeviceType(objDialog) {
	deviceTypeValidate();
	if ($("#frmDeviceType").valid()) {
		$(objDialog).dialog("close");
		var options ={
				type: "post",
				url : "ajaxSaveDeviceType.do",
				success: function (msg) {
					ajaxFindDeviceTypeSearchList();
					showMessageDialog("提示","设备类型保存成功。",null,dialogType.info);
				}
		};
		$("#frmDeviceType").ajaxSubmit(options);
	}
}

function ajaxSaveDeviceTypeProperty(objDialog) {
	if ($("#frmDeviceTypeProperty").valid()) {
		$(objDialog).dialog("close");
		var options ={
				type: "post",
				url : "ajaxSaveDeviceTypeProperty.do",
				success: function (msg) {
					ajaxFindDeviceTypeSearchList();
					showMessageDialog("提示","设备类型属性保存成功。",null,dialogType.info);
				}
		};
		$("#frmDeviceTypeProperty").ajaxSubmit(options);
	}
}

function ajaxDeleteDeviceTypeById(id) {
	var deviceTypeIds="";
	var sltDT = $("#listDeviceTypeList tbody input:checked").length;
	if(id==null){
		$("#listDeviceTypeList tbody input:checked").each(function(){ 
			deviceTypeIds += $(this).val()+";";
		});
		if(sltDT == 0){
			showMessageDialog("提示","请选择一行或多行",null,dialogType.info);
			return;
		}else{
			deviceTypeIds = deviceTypeIds.substring(0, deviceTypeIds.length-1);
		} 
	}else{
		deviceTypeIds=id;
		sltDT = 1;
	}
	if( deviceTypeIds!=null){
		showMessageDialog("删除设备类型信息","确定要删除所选"+sltDT+"条设备类型信息记录吗？",
				function () {
			$.ajax({     
				type:"post",
				url:"ajaxDeleteDeviceTypeByIds.do",
				data:{deviceTypeIds:deviceTypeIds},
				success:function(msg){
					ajaxFindDeviceTypeSearchList();
					showMessageDialog("提示","设备类型信息删除成功",null,dialogType.info);
				}
			});
		}
		,dialogType.warning);
	}
}

function deviceTypeValidate(){
	$("#frmDeviceType").validate({
		errorLabelContainer: $("#infoDeviceType"),
		rules : {
			deviceTypename : {
				required :true				
			},
			deviceTypedescribe : {
				required :true,
			}
		},
		messages : {
			deviceTypename : {
				required :"请输入设备名称！"
			},
			deviceTypedescribe : {
				required :"请输入设备描述！",
			}
		},
		success: function(label) {
			label.html("&nbsp;");
		}
	});
}
